home *** CD-ROM | disk | FTP | other *** search
- /*
- echo udp client - Usage: echoudp host
- */
-
-
- parse arg host .
-
- if host="" then do
- say "Usage: echoudp <host>"
- exit
- end
-
- addr = inetaddr(host)
- if addr == -1 then do
- if ~gethostbyname("HOST",host) then do
- say "Host" host "non trovato."
- exit
- end
- remote.ADDRADDR = HOST.HOSTADDRLIST.0
- end
- else remote.ADDRADDR = addr
-
- if ~getservbyname("SE","echo","udp") then do
- say "no echo udp service"
- exit
- end
-
- remote.ADDRFAMILY = "INET"
- remote.ADDRPORT = SE.SERVPORT
-
- sock = socket("INET","DGRAM","IP")
- if sock < 0 then do
- say "no socket:" ErrorString(Errno())
- exit
- end
-
- LOCAL.ADDRFAMILY = "INET"
- LOCAL.ADDRADDR = 0
- LOCAL.ADDRPORT = 0
- res = bind(sock,"LOCAL")
- if res < 0 then do
- say "Non posso allocare la porta:" Errno()
- exit
- end
-
- data = "echo udp service test"
- n = sendto(sock,data,0,"REMOTE")
- if n<length(data) then do
- say "send:" ErrorString(Errno())
- exit
- end
-
- n = recvfrom(sock,"BUF",256,0,"REMOTE")
- if len<0 then do
- say "recv:" ErrorString(Errno())
- exit
- end
- say buf
- call closesocket(sock)
-